import store from '@/store'

/**
 * 检查用户是否有权限访问某个模块
 * @param {string|Array} requiredRoles - 需要的角色，可以是字符串或数组
 * @returns {boolean} - 是否有权限
 */
export function hasPermission(requiredRoles) {
  const userRole = store.state.user.role
  
  if (!userRole) {
    return false
  }
  
  if (typeof requiredRoles === 'string') {
    return userRole === requiredRoles
  }
  
  if (Array.isArray(requiredRoles)) {
    return requiredRoles.includes(userRole)
  }
  
  return false
}

/**
 * 检查用户是否为教师
 * @returns {boolean}
 */
export function isTeacher() {
  return hasPermission('TEACHER')
}

/**
 * 检查用户是否为学生
 * @returns {boolean}
 */
export function isStudent() {
  return hasPermission('STUDENT')
}

/**
 * 获取用户角色
 * @returns {string}
 */
export function getUserRole() {
  return store.state.user.role
} 